package com.qf.cx.simplenms.webservice.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.qf.cx.simplenms.persist.entity.AntennaEntity;
import com.qf.cx.simplenms.persist.entity.ReaderGroupEntity;

public class ReaderGroup {
	private String name;
	private List<Long> antennaIds = Collections.emptyList();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Long> getAntennaIds() {
		return antennaIds;
	}

	public void setAntennaIds(List<Long> antennaIds) {
		this.antennaIds = antennaIds;
	}

	public static ReaderGroup from(ReaderGroupEntity readerGroupEntity) {
		ReaderGroup readerGroup = new ReaderGroup();
		readerGroup.name = readerGroupEntity.getName();
		List<Long> antennas = new ArrayList<>();
		readerGroupEntity.getAntennaEntities().forEach(t -> {
			antennas.add(t.getId());
		});
		readerGroup.setAntennaIds(antennas);
		return readerGroup;
	}

	public ReaderGroupEntity toReaderGroupEntity() {
		ReaderGroupEntity readerGroupEntity = new ReaderGroupEntity();
		readerGroupEntity.setName(name);

		List<AntennaEntity> antennaEntities = new ArrayList<>();
		antennaIds.forEach(t -> {
			AntennaEntity a = new AntennaEntity();
			// 此处只配置了ID
			a.setId(t);
			antennaEntities.add(a);
		});

		readerGroupEntity.setAntennaEntities(antennaEntities);
		return readerGroupEntity;
	}

	@Override
	public String toString() {
		return "ReaderGroup [name=" + name + ", antennaIds=" + antennaIds + "]";
	}
}
